import { useRequest, useUpdateEffect } from "ahooks";
import { userV1ControllerShowMine } from "@/services/auto/user";
import { setUserInfo } from "@/utils/tracker";

const useUser = () => {
  const {loading, data, runAsync, mutate} = useRequest(userV1ControllerShowMine, {
    manual: true,
  });

  if(!window.__mutateUserInfo){
    window.__mutateUserInfo = mutate;
  }

  useUpdateEffect(() => {
    if(data?.uuid){
      setUserInfo(data);
    }else{
      setUserInfo(undefined);
    }
  }, [data?.uuid]);

  return {
    loading,
    data,
    runAsync,
    mutate,
  };
};

export default useUser;
